#ifndef	__DBCS_CODE_PAGE_ENCODING_H__
#define	__DBCS_CODE_PAGE_ENCODING_H__

namespace BFX
{

class REFDBCSCodePageEncoding : public REFBaseCodePageEncoding
{
	//
	// Constructors
	//
public:
	REFDBCSCodePageEncoding(int nCodePage);
	REFDBCSCodePageEncoding(int nCodePage, int nDataCodePage);
	virtual ~REFDBCSCodePageEncoding();

	//
	// Overrides
	//
	virtual int GetMaxByteCount(int nCharCount) const;
	virtual int GetMaxCharCount(int nCount) const;

	virtual int GetByteCount(const UCHAR* pChars, int nCount) const;
	virtual int GetBytes(const UCHAR* pChars, int nCharCount, OUT BYTE* pBytes, int nByteCount) const;

	virtual int GetCharCount(const BYTE* pBytes, int nCount, REFDecoder* pDecoder) const;
	virtual int GetChars(const BYTE* pBytes, int nByteCount, OUT UCHAR* pChars, int nCharCount, REFDecoder* pDecoder) const;

	// Returns a Decoder object for this encoding. The returned object can be used to decode a sequence of bytes into a sequence of characters.
	// Contrary to the GetChars family of methods, a Decoder can convert partial sequences of bytes into partial sequences of characters
	// by maintaining the appropriate state between the conversions.
	virtual REFDecoder* GetDecoder() const;

protected:

	virtual void LoadManagedCodePage();

	// Any special processing for this code page
	virtual bool CleanUpBytes(INOUT int& nBytes) { return true; }

	// Any special processing for this code page
	virtual void CleanUpEndBytes(UCHAR* lpChars) {}

protected:
	//
	// The special decoder class for DBCS encoding.
	//
	class DBCSDecoder : public REFDecoder
	{
	public:
		DBCSDecoder(const REFEncoding* pEncoding);
		virtual ~DBCSDecoder();

		virtual void Reset();

	public:
		// Need a place for the last left over byte
		BYTE	m_byteLeftOver;
	};

	//
	// Attributes
	//
protected:
	UCHAR*	m_pMapBytesToUnicode;	// char 65536
	UINT16*	m_pMapUnicodeToBytes;	// byte 65536
	int*	m_pMapCodePageCached;	// to remember which CP is cached

};

}	//	namespace BFX

#endif	//	__DBCS_CODE_PAGE_ENCODING_H__
